var app = getApp();
var c = require("../libs/common.js");
var config = require('../libs/config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];  //上一个页面
    console.log(prevPage.data);
    var crb=prevPage.data.crb;
    var kqb=prevPage.data.kqb;
    var tnqc=prevPage.data.tnqc;
    var twqc=prevPage.data.twqc;
    if (crb[0]!=''){
      this.setData({ crb: crb})
    }else{
      this.setData({ crb: [] })
    }
    if (kqb[0] != '') {
      this.setData({ kqb: kqb })
    }else{
      this.setData({ kqb: [] })
    }
    if (tnqc[0] != '') {
      this.setData({ tnqc: tnqc })
    }else{
      this.setData({ tnqc: [] })
    }
    if (twqc[0] != '') {
      this.setData({ twqc: twqc })
    }else{
      this.setData({ twqc: [] })
    }
    this.setData({ prevPage: prevPage})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  bindDateAdd: function() {
    var myDate = new Date(); //获取系统当前时间
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var date = y + '-' + m + '-' + d;
    var kqb = this.data.kqb;
    var newData = date;
    kqb.push(newData);
    var index = kqb.length;
    this.setData({
      kqb: kqb
    })

  },
  bindDateAddcrb: function() {
    var myDate = new Date(); //获取系统当前时间
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var date = y + '-' + m + '-' + d;
    var crb = this.data.crb;
    var newData = date;
    crb.push(newData);
    var index = crb.length;
    this.setData({
      crb: crb
    })

  },
  bindDateAddtnqc: function() {
    var myDate = new Date(); //获取系统当前时间
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var date = y + '-' + m + '-' + d;
    var tnqc = this.data.tnqc;
    var newData = date;
    tnqc.push(newData);
    var index = tnqc.length;
    this.setData({
      tnqc: tnqc
    })

  },
  bindDateAddtwqc: function() {
    var myDate = new Date(); //获取系统当前时间
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var date = y + '-' + m + '-' + d;
    var twqc = this.data.twqc;
    var newData = date;
    twqc.push(newData);
    var index = twqc.length;
    this.setData({
      twqc: twqc
    })
  },
  bindDateChangekqb: function(e) {
    var date = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var kqb = this.data.kqb;
    var kqbindex = 'kqb[' + index + ']';
    this.setData({
      [kqbindex]: date
    })
  },
  bindDateChangekqbadd: function(e) {
    var date = e.detail.value;
    var len = this.data.kqb.length - 1;
    var kqbindex = 'kqb[' + len + ']';
    var prevPage = this.data.prevPage;
    prevPage.setData({
      [kqbindex]: date
    })
    this.setData({
      [kqbindex]: date
    })
  },
  bindDateChangecrb: function(e) {
    var date = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var crb = this.data.crb;
    var crbindex = 'crb[' + index + ']';
    var prevPage = this.data.prevPage;
    prevPage.setData({
      [crbindex]: date
    })
    this.setData({
      [crbindex]: date
    })
  },
  bindDateChangecrbadd: function(e) {
    var date = e.detail.value;
    var len = this.data.crb.length - 1;
    var crbindex = 'crb[' + len + ']';
    var prevPage = this.data.prevPage;
    prevPage.setData({
      [crbindex]: date
    })
    this.setData({
      [crbindex]: date
    })
  },
  bindDateChangetnqc: function(e) {
    var date = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var tnqc = this.data.tnqc;
    var tnqcindex = 'tnqc[' + index + ']';
    this.setData({
      [tnqcindex]: date
    })
  },
  bindDateChangetnqcadd: function(e) {
    var date = e.detail.value;
    var len = this.data.tnqc.length - 1;
    var tnqcindex = 'tnqc[' + len + ']';
    var prevPage = this.data.prevPage;
    prevPage.setData({
      [tnqcindex]: date
    })
    this.setData({
      [tnqcindex]: date
    })
  },
  bindDateChangetwqc: function(e) {
    var date = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var twqc = this.data.twqc;
    var twqcindex = 'twqc[' + index + ']';
    this.setData({
      [twqcindex]: date
    })
  },
  bindDateChangetwqcadd: function(e) {
    var date = e.detail.value;
    var len = this.data.twqc.length - 1;
    var twqcindex = 'twqc[' + len + ']';
    var prevPage = this.data.prevPage;
    prevPage.setData({
      [twqcindex]: date
    })
    this.setData({
      [twqcindex]: date
    })
  },
  bindDateDelete: function(e) {
    var index = e.currentTarget.dataset.id;
    var that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          var kqb = that.data.kqb;
          var kqbnew = kqb.splice(index, 1);
          that.setData({
            kqb: kqb
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  bindDateDeletecrb: function(e) {
    var index = e.currentTarget.dataset.id;
    var that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          var crb = that.data.crb;
          var crbnew = crb.splice(index, 1);
          that.setData({
            crb: crb
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  bindDateDeletetnqc: function(e) {
    var index = e.currentTarget.dataset.id;
    var that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          var tnqc = that.data.tnqc;
          var tnqcnew = tnqc.splice(index, 1);
          that.setData({
            tnqc: tnqc
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  bindDateDeletetwqc: function(e) {
    var index = e.currentTarget.dataset.id;
    var that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          var twqc = that.data.twqc;
          var twqcnew = twqc.splice(index, 1);
          that.setData({
            twqc: twqc
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  }

})